package cn.fyl.pet.service.impl;

import cn.fyl.basic.service.impl.BaseServiceImpl;
import cn.fyl.pet.domain.Pet;
import cn.fyl.pet.domain.PetDetail;
import cn.fyl.pet.mapper.PetDetailMapper;
import cn.fyl.pet.mapper.PetMapper;
import cn.fyl.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Autowired
    private PetMapper petMapper;

    @Override
    public void save(Pet pet) {
        petMapper.save(pet);

        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);

    }

    @Override
    public void update(Pet pet) {
        petMapper.update(pet);
        petDetailMapper.update(pet.getPetDetail());
    }

    @Override
    public void remove(Long id) {
        super.remove(id);
        petDetailMapper.remove(id);
    }

    @Override
    public void onSale(List<Long> ids) {
        Date date = new Date();
        petMapper.onSale(ids,date);

    }

    @Override
    public void offSale(List<Long> ids) {

        Date date = new Date();
        petMapper.offSale(ids,date);

    }


}